import 'package:flutter/cupertino.dart';
import 'package:razer_one/app/main/model/status_model.dart';

class MainLoadMoreView extends StatelessWidget {
  final StatusModel statusModel;
  final Function netErrorHandle;

  const MainLoadMoreView({
    Key? key,
    required this.netErrorHandle,
    required this.statusModel,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    String title = "";
    //没有更多
    if (!statusModel.isHaveMore) {
      title = "我是有底线的";
    } else if (statusModel.isLoading) {
      title = "努力加载中...";
    } else if (statusModel.isLoadMoreError) {
      title = "当前网络不可用,点击重新加载";
    } else {
      // title = "点击或上拉加载更多";
      title = "努力加载中...";
    }
    return GestureDetector(
      behavior: HitTestBehavior.translucent,
      onTap: () {
        // if (!statusModel.isLoading && statusModel.isHaveMore) {
        //   netErrorHandle();
        // }
        if (statusModel.isLoadMoreError) {
          netErrorHandle();
        }
      },
      child: Container(
        padding: const EdgeInsets.only(top: 10, bottom: 50),
        alignment: Alignment.center,
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          children: [
            Visibility(
                visible:
                    (!statusModel.isLoadMoreError && statusModel.isHaveMore),
                child: const CupertinoActivityIndicator(
                  radius: 10,
                )),
            const SizedBox(
              width: 10,
            ),
            Text(
              title,
            )
          ],
        ),
      ),
    );
  }
}
